<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{$title}</title>
<include file='web/common:source'/>
<style>
div.layui-layer-shade{background-color:rgba(255,255,255,0) !important;}
div.layui-layer-rim{border:none; box-shadow:3px 5px 6px #dadada,-3px -1px 6px #dadada;}
div.layui-layer-title{background-color:#e2e5e8;}
</style>
</head>
<body ng-app="myApp" ng-controller="myAppControl">
<div class="mainBox m o">
    <div class="mainRight fr" style="padding-bottom:0px;">
        <include file='web/common:header'/>
        <div class="mainRightBot pr o">
            <!-- leftMenu start -->
            <include file='web/common:left'/>
            <!-- leftMenu end -->
            <div class="rightBox fr" style="width:940px; min-height:900px;">
                <!-- rightBoxTop start -->
                <include file='web/project:common'/>
                <!-- rightBoxTop end -->
                <div class="rightBoxBot">
                	<div class="rightBoxBotTop o afl">
						<a href="">返回上一级</a>
						<a href="{:U('Project/index')}" class="ts300">项目列表</a>
						<a class="lt"><i class="layui-icon" style="font-size: 16px;">&#xe602;</i></a>
						<a href="{:U('Project/detail',array('id'=>$_GET['id']))}" class="ts300">项目详情</a>
                        <a class="lt"><i class="layui-icon" style="font-size: 16px;">&#xe602;</i></a>
                        <a class="ts300">项目资源</a>
                	</div>
                    <div class="ziyuanMid ab afr" style="width:900px;"><a href="javascript:;" onclick="shangchuanShadow()" class="ts300">+&nbsp;我要上传</a></div>
                	<div class="ziyuanBottom m">
                        <ul class="w120 o ab">
                            <li><a href="{:U('Project/attachmentList',array('type'=>10))}" class="ts300"><img src="__ROOT__/static/web/images/img29.png" alt=""><h3 class='f100'>会议纪要</h3></a></li>
                            <li><a href="{:U('Project/attachmentList',array('type'=>11))}" class="ts300"><img src="__ROOT__/static/web/images/img30.png" alt=""><h3 class='f100'>合同文本</h3></a></li>
                            <li><a href="{:U('Project/attachmentList',array('type'=>12))}" class="ts300"><img src="__ROOT__/static/web/images/img31.png" alt=""><h3 class='f100'>图片</h3></a></li>
                            <li><a href="{:U('Project/attachmentList',array('type'=>13))}" class="ts300"><img src="__ROOT__/static/web/images/img32.png" alt=""><h3 class='f100'>图纸</h3></a></li>
                            <li><a href="{:U('Project/attachmentList',array('type'=>14))}" class="ts300"><img src="__ROOT__/static/web/images/img33.png" alt=""><h3 class='f100'>URL</h3></a></li>
                            <li><a href="{:U('Project/attachmentList',array('type'=>15))}" class="ts300"><img src="__ROOT__/static/web/images/img34.png" alt=""><h3 class='f100'>其它</h3></a></li> 
                        </ul>
                    </div>
                </div>           
                <!-- 新建订单 弹出层 start -->
                <include file='web/common:createDingdan'/>
                <!-- 新建订单 弹出层 end -->
                <!-- 新建项目 弹出层 新建项目 start -->
                <include file='web/common:createProject'/>
                <!-- 新建项目 弹出层 end -->
                <!-- 新建合同 弹出层 start -->
                <include file='web/common:createHetong'/>
                <!-- 新建合同 弹出层 end -->
                <!-- 弹出层 我要上传 start -->
	            <div id="xiangmuShadow" class="o shangchuanShadow dn pr">
	                <div class="dingdanShadowBox palt">
	                    <div class="dingdanShadowBoxBox o">
	                        <div class="dingdanTop" style="padding-bottom:0px;">
	                            <dl class="dingdanCom pr">
	                                <dt class="palt">*</dt>
	                                <dd class="text w120 o">
	                                    <span class="ib title fl">资源名称：</span>
	                                    <input type="text" name="ziyuanName" class="fl txt" placeholder="点击输入">
	                                </dd>
	                            </dl>
	                            <!-- <dl class="dingdanCom pr">
	                                <dt class="palt">*</dt>
	                                <dd class="text w120 o">
	                                    <span class="ib title fl">上&nbsp;&nbsp;传&nbsp;&nbsp;者：</span>
	                                    <input type="text" class="fl txt" placeholder="点击输入">
	                                </dd>
	                            </dl> -->
	                            <style type="text/css">
								dl.dingdanCom.zizhiInput dd.text:after{left:310px; top:10px;}
								dl.dingdanComRadio dd.text span.radioItem{padding-right:30px;}
								dl.dingdanComRadio dd.text span.radioItem input{cursor:pointer;}
								dl.dingdanComRadio dd.text span.radioItem label{color:#979797; font-size:16px; cursor:pointer;}
								dl.dingdanUrl dd.text a.addUrl{display:inline-block; width:50px; text-align:center; height:38px; line-height:37px; border-radius: 5px; font-size:16px; color:#fff; background:#3296F3; float:left; margin-left:10px;}
	                            </style>
	                            <dl class="dingdanCom  dingdanComRadio pr">
	                                <dt class="palt">*</dt>
	                                <dd class="text o">
	                                    <span class="ib title fl" style="line-height:40px;">资源类型：</span>
	                                    <div class="radioBox fl">
	                                    	<span class="radioItem">
	                                    		<input type="radio" checked ng-click="typeSelect(1)" id="type1" name="uploadType" value="10" title="会议纪要">
		                                    	<label for="type1">会议纪要</label>	   
	                                        </span>
	                                        <span class="radioItem">		                                    	
		                                        <input type="radio" ng-click="typeSelect(2)" id="type2" name="uploadType" value="11" title="项目合同文本">
		                                        <label for="type2">项目合同文本</label>
	                                        </span>
	                                        <span class="radioItem">		                                    	
		                                        <input type="radio" ng-click="typeSelect(3)" id="type3" name="uploadType" value="12" title="项目图片">
		                                        <label for="type3">项目图片</label>
	                                        </span>
	                                        <span class="radioItem">		                                    	
		                                        <input type="radio" ng-click="typeSelect(4)" id="type4" name="uploadType" value="13" title="项目图纸">
		                                        <label for="type4">项目图纸</label>
	                                        </span>
	                                        <span class="radioItem">		                                    	
		                                        <input type="radio" ng-click="typeSelect(5)" id="type5" name="uploadType" value="14" title="URL">
		                                        <label for="type5">URL</label>
	                                        </span>
	                                        <span class="radioItem">		                                    	
		                                        <input type="radio" ng-click="typeSelect(6)" id="type6" name="uploadType" value="15" title="其他">
		                                        <label for="type6">其他</label>
	                                        </span>
	                                    </div>
	                                </dd>
	                            </dl>
	                            <div class="dingdanUrlBox">
		                            <dl class="dingdanCom dingdanUrl pr" ng-show="urlShow">
		                                <dt class="palt">*</dt>
		                                <dd class="text w120 o">
		                                    <span class="ib title fl">URL：</span>
		                                    <input type="text" style="width:385px;" class="fl txt urlInput" placeholder="输入要上传的URL">
		                                    <a class="addUrl" data-onOff="false" href="javascript:;">增加</a>
		                                </dd>
		                            </dl>		                           
	                            </div>
	                            <dl class="dingdanCom zizhiInput selectInput pr" ng-hide="urlShow">
	                                <dt class="palt">*</dt>
	                                <dd class="text o">
	                                    <span class="ib title fl">选择要上传的文件：</span>
	                                    <input type="text" class="fl txt" id="uploadFile" placeholder="请选择上传的文件" readonly="readonly">
	                                </dd>
	                            </dl>
	                            <style type="text/css">
								ul.showUploadList{width:580px; margin:0px auto; padding-bottom:10px;}
								ul.showUploadList li{padding-bottom:10px;}
	                            ul.showUploadList li i{color:#c90000; font-weight:bold;}
	                            ul.showUploadList li a{font-size:16px; color:#979797; padding-left:10px;}
	                            </style>
	                            <ul class="showUploadList"></ul>
	                            <!-- <dl class="dingdanCom pr">
	                                <dt class="palt">*</dt>
	                                <dd class="text w120 c pr">
	                                    <span class="ib title fl">品种类别：</span>
	                                    <select name="city" class="comSelect" lay-verify="required">
	                                        <option value=""></option>
	                                        <option value="0">品种类别A</option>
	                                        <option value="1">品种类别B</option>
	                                        <option value="2">品种类别C</option>
	                                        <option value="3">品种类别D</option>
	                                        <option value="4">品种类别E</option>
	                                    </select>
	                                </dd>
	                            </dl> -->
	                            <!-- <ul class="uploadImg uploadDoc">
	                                <li>
	                                    <i class="layui-icon cp">&#x1006;</i>
	                                    <h3 class="f100">2018年1月4日会议纲要</h3>
	                                    <img src="__ROOT__/static/web/images/img58.png" alt=""> 
	                                </li>
	                                <li>
	                                    <i class="layui-icon cp">&#x1006;</i>
	                                    <h3 class="f100">统计表格</h3>
	                                    <img src="__ROOT__/static/web/images/img59.png" alt=""> 
	                                </li>                                
	                            </ul> --> 
	                        </div>
	                        <div class="dingdanBot" style="padding-bottom:20px;">
	                            <input type="button" class="submit" value="确认上传资源">
	                        </div>
	                    </div>
	                </div>
	            </div>
	            <!-- 弹出层 我要上传 end -->
            </div>
        </div>
    </div>
</div>
</body>
<include file='web/common:footer'/>
<script type="text/javascript">
// layui.use('form',function(){});
// /service/uploadUrl
var hostUrl = "http://"+"<?php echo $_SERVER['HTTP_HOST']; ?>/";
var uploadUrl = hostUrl+"service/upload"; 
var uploadurlUrl= hostUrl+"service/uploadUrl";
var uploadZiyuanUrl = hostUrl+"check/applyattachment";
// angular start
angular.module("myApp",[]).controller('myAppControl',['$scope',function($scope){
	$scope.urlShow = false;
	$scope.typeSelect = function(curType){
		if(curType == 5){
			$scope.urlShow = true;
		}else{
			$scope.urlShow = false;
		};
	};
}]);
var urlStr = "";
$("div.dingdanUrlBox").find('input.urlInput').live('blur',function(){
	//$(this).siblings("a.addUrl").attr('data-onOff');
	var that = $(this);
	var curUrl = $(this).val();
	var curArr = [];
	if(curUrl == null || curUrl == ""){
		layer.alert('请输入需要上传的URL');
		return false;
	};
	curArr.push(curUrl);
	$.post(uploadurlUrl,{urls:curArr},function(res){
		if(res.message == "OK"){
			layer.alert('添加成功');
			urlStr += publicLiStr(res);
			$("ul.showUploadList").html(urlStr);
			that.siblings("a.addUrl").attr('data-onOff','true');
		}else{
			layer.alert(res.message);
		};
	},'json');
});
$("div.dingdanUrlBox").find('a.addUrl').live('click',function(){
	if($(this).attr('data-onOff') != "false"){
		$("div.dingdanUrlBox").find("a.addUrl").remove();
		var oStr = "<dl class='dingdanCom dingdanUrl pr' ng-show='urlShow'><dt class='palt'>*</dt><dd class='text w120 o'><span class='ib title fl'>URL：</span><input type='text' style='width:385px;' class='fl txt urlInput' placeholder='输入要上传的URL'><a class='addUrl' data-onOff='false' href='javascript:;'>增加</a></dd></dl>";
		$("div.dingdanUrlBox").append(oStr);
	};
});
$("div.dingdanBot input.submit").click(function(){
	var ziyuanName = $("dl.dingdanCom input[name='ziyuanName']").val();
	var uploadType = $("dl.dingdanComRadio").find("input[name='uploadType']").filter(':checked').val();	
	var oIdArr = [];
	var postData = {};
	if(ziyuanName == "" || ziyuanName == null){
		layer.alert('请输入资源名称');
		return false;
	};
	if($("ul.showUploadList li").size() == 0){
		layer.alert('请先选择要上传的文件');
		return false;
	};
	$("ul.showUploadList li").each(function(index,item){
		oIdArr.push($(this).attr('data-id')); 
	});
	$.post(uploadZiyuanUrl,{project_id:<?php echo $_GET['id'];?>,name:ziyuanName,type:uploadType,attachments:oIdArr},function(res){
		if(res.message == "OK"){
			layer.confirm('上传成功', function(index){				
               layer.close(index);
               location.reload();
            });
		}else{
			layer.alert(res.message);
		};
	},'json');
	// if(uploadType != 14){
	// 	if($("ul.showUploadList li").size() == 0){
	// 		layer.alert('请先选择要上传的文件');
	// 		return false;
	// 	};
	// 	curUploadUrl = uploadZiyuanUrl;
	// 	$("ul.showUploadList li").each(function(index,item){
	// 		oIdArr.push($(this).attr('data-id')); 
	// 	});
	// 	postData = 	{project_id:<?php echo $_GET['id'];?>,name:ziyuanName,type:uploadType,attachments:oIdArr};
	// }else if(uploadType == 14){
	// 	curUploadUrl = uploadurlUrl;
	// 	$("div.dingdanUrlBox dl.dingdanUrl").each(function(index,item){
	// 		var curUrlLink = $(this).find("input.urlInput").val();
	// 		if(curUrlLink != null || curUrlLink != ''){
	// 			oIdArr.push(curUrlLink);
	// 		};
	// 	});
	// 	// postData = 	{project_id:<?php echo $_GET['id'];?>,name:ziyuanName,type:uploadType,urls:oIdArr};
	// 	postData = {urls:oIdArr};
	// };
	// $.post(curUploadUrl,postData,function(res){
	// 	if(res.message == "OK"){
	// 		layer.confirm('上传成功', function(index){				
 //               layer.close(index);
 //               location.reload();
 //            });
	// 	}else{
	// 		layer.alert(res.message);
	// 	};
	// },'json');
});
// var uploadType = null;
// $("#uploadFile").click(function(){
// 	uploadType = $("dl.dingdanComRadio").find("input[name='uploadType']").filter(':checked').val();
// 	if(uploadType == null || uploadType == ''){
// 		layer.alert('请先选择上传的资源类型');
// 		return false;
// 	}else{
// 		$(this).trigger('click');
// 	};	
// });
var fileStr = ""
layui.use('upload', function(){
	var upload = layui.upload;
	var uploadInst = upload.render({
		elem: '#uploadFile',
		multiple: true,
		accept:'file',
		url: uploadUrl,
		done: function(res){
			fileStr += publicLiStr(res);
			$("ul.showUploadList").html(fileStr);
		},
		error: function(){
			layer.alert('上传失败'); 
		}
	});
});
function publicLiStr(res){
	var publicLiStr = "<li data-id='"+res.data[0].id+"'><i class='layui-icon cp'>&#x1006;</i><a target='_blank' href='"+res.data[0].path+"'>"+res.data[0].name+"</a></li>";
	return publicLiStr;
	//$("ul.showUploadList").append(publicLiStr);
};
$("ul.showUploadList li").find('i.layui-icon').live('click',function(){
	$(this).parent().remove();
});
shangchuanShadow();
function shangchuanShadow(){
    layer.open({
        type: 1,
        scrollbar:false,
        title: ['上传资源', 'font-size:18px;'],
        skin: 'layui-layer-rim', //加上边框
        area: ['650px', '650px'], //宽高
        content: $(".shangchuanShadow")
    });
};
</script>
</html>